package cn.tj.wenda.cloud.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * json 解析类，通用于全项目
 * @author Wenda
 */
@Slf4j
public class JsonUtils {

    private static ObjectMapper objectMapper = new ObjectMapper();

    /**
     * 将Bean转成Json字符串
     * @param o
     * @return
     */
    public static String objectToJsonStr(Object o) {
        try {
            return objectMapper.writeValueAsString(o);
        } catch (IOException e) {
            log.error("Bean 转为Json时出错：", e);
        }
        return "";
    }
}
